#ifndef __SLOTHTTPD_HTTP_REQUEST_HPP__
#define __SLOTHTTPD_HTTP_REQUEST_HPP__

#include <slothttpd/types.hpp>
#include <slothttpd/data_buffer.hpp>
#include <slothttpd/request_header.hpp>
#include <slothttpd/http/status.hpp>
#include <slothttpd/http/method.hpp>

#include <ostream>

namespace slothttpd {
namespace http {

typedef std::pair<int, int> version_t;

class request
{
public:
    // TODO: save post data into file
    struct content_t
    {
        char_range_t        header_value;
        
        std::size_t         length;
        char               *data;
        std::size_t         bytes_received;
    };
    
    request();
    
    version_t           http_version;
    method::method_type method_;
    char_range_t        method_name;
    char_range_t        schema;
    char_range_t        host;
    char_range_t        port;
    char_range_t        path;
    char_range_t        path_extension;
    char_range_t        query_string;
    
    request_header_list headers;
    
    content_t          *content;
    char_range_t        content_type;
    bool                keep_alive;
    
    const status::status_type& unescape_path();
    
    static char_range_t unescape_uri(char_range_t src, char *dst, char_range_t &extension) noexcept;
};

std::ostream &operator<<(std::ostream &os, const request &req);

}
}

#endif
